using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Collections;
using Easily._02_Form._01_frmCtrlConfig;
using System.Media;

namespace Easily
{
    ///==============================================================================
    /// <summary>
    /// 功能说明：通用控件。该图标有一个入口和一个出口。以前版本的图标有一个入口，
    /// 多个出口的，现在全部统一为一个入口和一个出口。该类提供了图标的拖拽效果等功能。
    /// </summary>
    ///==============================================================================
    public class GeneralIcon : Icon
    {
        #region GeneralIcon类的字段
        ///==============================================================================
        // 通用控件的类型（枚举）
        public enum TypeOfGeneralIcon
        {
            EventIcon,       //事件控件(中断)
            ExecuteIcon,     //执行控件
            SensorIcon,      //传感器控件
            CommunicateIcon, //通信控件
            FlowControl,     //流控制控件
            SubFunIcon,      //子程序控件
            NULL,            //无
        }
        //[2021/4/28]音乐播放
        SoundPlayer sp = new SoundPlayer();
        public TypeOfGeneralIcon GeneralIconType;   //记录当前控件的类型

        //通用控件图片的连接点图片及相关的高度宽度信息
        //鼠标未移动至出或入连接点的两张图片
        public PictureBox InPic1 = new PictureBox();
        public int IconInPic1Height;//20150913去除,程序中没有真正使用它？
        public int IconInPic1Width;
        public PictureBox OutPic1 = new PictureBox();
        public int IconOutPic1Height;
        public int IconOutPic1Width;
        //鼠标移动至出或入连接点的两张图片
        public PictureBox InPic2 = new PictureBox();
        public int IconInPic2Height;
        public int IconInPic2Width;
        public PictureBox OutPic2 = new PictureBox();
        public int IconOutPic2Height;
        public int IconOutPic2Width;
        //注释的图片
        public PictureBox notePic = new PictureBox();
        public int notePicHeight;
        public int notePicWidth;

        public int IconFuncType; //区分主程序=1；子程序=2

        public LinkIconType ParentType;//父控件的类型
        public LinkIconType ChildType;//子控件的类型

        public Icon Parent;         //控件的父控件
        public int ParentIconArrNum;//控件的父控件在其相应链表中的位置
        public Icon Child;          //控件的子控件
        public int ChildIconArrNum; //控件的子控件在其相应链表中的位置

        public int ChildDotX;       //控件的子控件的接入点坐标X
        public int ChildDotY;       //控件的子控件的接入点坐标Y
        //public string code.InsertCode;//通用控件的代码

        public Code code = null;//[2018]
        public LoadConfig.Control info;//[2019]

        public string FuncName;      //函数名
        public string FuncRetStyle;  //函数返回值类型
        public string FuncDes;       //函数描述，注释
        public string FuncRetDes;    //函数返回值描述
        public int FuncParCount;     //函数参数个数
        public ArrayList FuncParInfo = new ArrayList();//函数参数信息

        public Form GeneralIconSetting = null;//存储控件窗体的基类


        // 快捷菜单类，用于点击鼠标右键弹出的快捷菜单150913注释
        private ContextMenuStrip GeneralIconContextMenuStrip = new ContextMenuStrip();

        ///==============================================================================
        #endregion

        #region GeneralIcon类的方法
        ///==============================================================================

        //GeneralIcon类构造函数
        public GeneralIcon()
        {
            this.code = new Code();//[2018]

            //初始化GeneralIcon类的字段
            this.IconType = GeneralIcon.LinkIconType.GeneralIcon;
            this.GeneralIconType = GeneralIcon.TypeOfGeneralIcon.NULL;
            this.ParentType = GeneralIcon.LinkIconType.NULL;
            this.ChildType = GeneralIcon.LinkIconType.NULL;
            Parent = Child = null;
            ParentIconArrNum = ChildIconArrNum = -1;
            ChildDotX = ChildDotY = -1;
            this.code.InsertCode = "";
            this.code.Comment = string.Empty;
            this.IconName = "";

            //设置控件连接点图片的图片显示方式
            this.InPic1.SizeMode = PictureBoxSizeMode.StretchImage;  //设置图像填满图片控件
            this.OutPic1.SizeMode = PictureBoxSizeMode.StretchImage;
            //【调整出入点大小，原来为8】
            this.InPic1.Height = (int)(Globaldefine.DotSize * 10);    //设置图片控件的高
            this.InPic1.Width = (int)(Globaldefine.DotSize * 10);     //设置图片控件的宽
            this.OutPic1.Height = (int)(Globaldefine.DotSize * 10);
            this.OutPic1.Width = (int)(Globaldefine.DotSize * 10);
            this.InPic1.Refresh();                                   //刷新显示图片控件
            this.OutPic1.Refresh();
            this.InPic2.SizeMode = PictureBoxSizeMode.StretchImage;
            this.OutPic2.SizeMode = PictureBoxSizeMode.StretchImage;
            this.InPic2.Height = (int)(Globaldefine.DotSize * 16);
            this.InPic2.Width = (int)(Globaldefine.DotSize * 16);
            this.OutPic2.Height = (int)(Globaldefine.DotSize * 16);
            this.OutPic2.Width = (int)(Globaldefine.DotSize * 16);
            this.InPic2.BackColor = Color.Transparent;
            this.OutPic2.BackColor = Color.Transparent;
            this.InPic2.Refresh();
            this.OutPic2.Refresh();
            this.notePic.SizeMode = PictureBoxSizeMode.StretchImage;
            this.notePic.Height = (int)(Globaldefine.DotSize * 28);
            this.notePic.Width = (int)(Globaldefine.DotSize * 16);
            this.notePic.BackColor = Color.Transparent;
            this.notePic.Refresh();
            
            //注册与控件相关的事件
            //注册鼠标移动至控件并按下的事件
            this.MoveToIconPicBox.MouseDown += new MouseEventHandler(IconPicBox_MouseDown);
            //注册鼠标移动至控件并抬起的事件
            this.MoveToIconPicBox.MouseUp += new MouseEventHandler(GeneralIconPicBox_MouseUp);
            //注册鼠标移动至控件的事件
            this.IconPicBox.MouseEnter += new EventHandler(IconPicBox_MouseEnter);
            //注册鼠标移动至控件并离开的事件
            this.MoveToIconPicBox.MouseLeave += new EventHandler(MoveToIconPicBox_MouseLeave);
            //注册鼠标移动至控件并双击的事件
            this.MoveToIconPicBox.DoubleClick += new EventHandler(MoveToIconPicBox_DoubleClick);

            //注册在控件上单击右键显示的菜单列表
            GeneralIconContextMenuStrip.Items.Add("剪切");
            GeneralIconContextMenuStrip.Items.Add("复制");
            GeneralIconContextMenuStrip.Items.Add("删除");
            //注册右键菜单被点击后触发的事件
            GeneralIconContextMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(GeneralIconContextMenuStrip_ItemClicked);
           
        }

        //从arrIconBoxInfo读取函数控件信息
        public void LoadCtrlFunc(string IconName)
        {
            //int i, j;

            //for (i = 0; i < Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo.Count; i += (Globaldefine.IconInfoSize + 1))
            //{
            //    if (Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i + 1].ToString() == IconName)
            //    {
            //        FuncName = Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i+4].ToString();
            //        FuncDes = Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i+5].ToString();
            //        FuncRetStyle = Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i+6].ToString();
            //        FuncRetDes = Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i+7].ToString();
            //        FuncParCount = Convert.ToInt32(Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i+8]);
            //        FuncParInfo.Clear();
            //        for (j = 0; j < FuncParCount; j++)
            //        {
            //            FuncParInfo.Add(Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i + 9 + j * 3].ToString());
            //            FuncParInfo.Add(Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i + 10 + j * 3].ToString());
            //            FuncParInfo.Add(Globaldefine.FrmParent.InfoOfIconBox.arrIconBoxInfo[i + 11 + j * 3].ToString());
            //        }
            //    }
            //}
        }
        public void LoadCtrlImage(string name, int x, int y, PictureBox tempPic1, PictureBox tempPic2, frmGraphicProgrammer frm, bool IsSubFunc)
        {                            //frmGraphicProgrammer为图形化编程面板窗体类 
            Image img;
            IsSubFunc = false;  //删除子程序单独处理的概念【20190425】
            if (IsSubFunc)
            {
                string path = Directory.GetParent(Directory.GetParent(Application.StartupPath).FullName).FullName;
                this.IconLeftDotNum = x;
                this.IconTopDotNum = y;
                //两张图片重叠，在鼠标移入、移出时显示不同图片
                img = Image.FromFile(Globaldefine.exePath + @"Resource\IconBox\SubFunRoot1.png");
                tempPic1.Image = img;
                tempPic1.Left = (int)(this.IconLeftDotNum * Globaldefine.DotSize * 15);
                tempPic1.Top = (int)(this.IconTopDotNum * Globaldefine.DotSize * 15);

                img = Image.FromFile(Globaldefine.exePath + @"Resource\IconBox\SubFunRoot2.png");
                tempPic2.Image = img;
                tempPic2.Left = tempPic1.Left;
                tempPic2.Top = tempPic1.Top;
                tempPic2.Visible = false;
            }
            else
            {
                this.IconLeftDotNum = x;
                this.IconTopDotNum = y;
                img = Image.FromFile(Globaldefine.exePath + @"Resource\IconImage\Execute\" + 
                    Globaldefine.loadConfig.controlIconDic[name].image3);
                tempPic1.Image = img;
                //这里的X,Y坐标和图形化面板的坐标不一致，需要一个平移
                tempPic1.Left = (int)(this.IconLeftDotNum * Globaldefine.DotSize * 15);
                tempPic1.Top = (int)(this.IconTopDotNum * Globaldefine.DotSize * 15);
                //if (name == "开始")
                //    img = Image.FromFile(Globaldefine.FrmParent.InfoOfIconBox.controlIconDic[name].image1);
                //else
                img = Image.FromFile(Globaldefine.exePath + @"Resource\IconImage\Execute\" + 
                    Globaldefine.loadConfig.controlIconDic[name].image2);//20160323修改
                tempPic2.Image = img;
                tempPic2.Left = tempPic1.Left;
                tempPic2.Top = tempPic1.Top;
                tempPic2.Visible = false;
            }
        }

        //创建通用图标控件
        public void CreateGeneralImage(TypeOfGeneralIcon Type, string ModuleName,string IconName,
            int x, int y, frmGraphicProgrammer frm, bool IsSubFunc)
        {
            IsSubFunc = false;  //删除子程序单独处理的概念【20190425】
            //初始化控件信息
            this.GeneralIconType = Type;    //通用控件类型
            this.ModuleName = ModuleName;     //控件名字
            this.IconName = IconName;
            this.info = Globaldefine.loadConfig.controlIconDic[ModuleName];
            string hardType = info.hard_type;
            //if (Globaldefine.FrmParent.InfoOfIconBox.controlIconDic.ContainsKey(ModuleName))
            //    hardType = Globaldefine.FrmParent.InfoOfIconBox.controlIconDic[ModuleName].controlHardType;
            //【添加控件】
            //根据控件名打开不同的窗体
            if (this.ModuleName == "延时")
            {
                GeneralIconSetting = new frmTimedelaySet(this);
            }
            else if (this.ModuleName == "写入代码")
            {
                GeneralIconSetting = new frminput_code(this);
            }
            else if(this.ModuleName == "NB-IoT初始化")
            {
                GeneralIconSetting = new frmUEcomInit(this);
            }
            else if (this.ModuleName == "NB-IoT发送数据")
            {
                GeneralIconSetting = new frmUEcomSend(this);
            }
            else if (this.ModuleName == "WIFI初始化")
            {
                GeneralIconSetting = new frmUEcomInit(this);
            }
            else if (this.ModuleName == "WIFI发送数据")
            {
                GeneralIconSetting = new frmUEcomSend(this);
            }
            else if (this.ModuleName == "串口发送数据")
            {
                GeneralIconSetting = new frmUartSend(this);
            }
            else if (this.ModuleName == "接收到串口数据")
            {
                GeneralIconSetting = new frmUartRecv(this);
            }
            else if (this.ModuleName == "定时器时间到")
            {
                GeneralIconSetting = new frmTimeArrive(this);
            }
            else if (this.ModuleName == "接收到WIFI数据")
            {
                GeneralIconSetting = new frmUEcomRecv(this);
            }
            else if (this.ModuleName == "SPI发送数据")
            {
                GeneralIconSetting = new frmSPISend(this);
            }
            else if (this.ModuleName == "IIC")
            {
                GeneralIconSetting = new frmIIC(this);
            }
            else if (this.ModuleName == "LCD显示")
            {
                GeneralIconSetting = new frmLCD(this);
            }
            else if (this.ModuleName == "TSEV温度传感器")
            {
                GeneralIconSetting = new frmTESV(this);
            }
            else if (this.ModuleName == "条件循环")
            {
                GeneralIconSetting = new frmCnd_Loop(this);
            }
            else if ((this.ModuleName == "单分支") || (this.ModuleName == "双分支"))
            {
                GeneralIconSetting = new frmCnd_Loop(this);
            }
            else if (this.ModuleName == "计数循环")
            {
                GeneralIconSetting = new frmCountLoop(this);
            }
            else if (this.ModuleName == "定义函数")
            {
                GeneralIconSetting = new frmFunDefine(this);
            }
            else if (this.ModuleName == "调用函数")
            {
                GeneralIconSetting = new frmFunCall(this);
            }
            else if (this.ModuleName == "printf")
            {
                GeneralIconSetting = new frmPrintf(this);
            }
            else if (this.ModuleName == "定义变量")
            {
                GeneralIconSetting = new frmVariableInit(this);
            }
            else if (this.ModuleName == "设置变量")
            {
                GeneralIconSetting = new frmVariableSet(this);
            }
            else if (this.ModuleName == "数码管模块")
            {
                GeneralIconSetting = new frmDigit(this);
            }
            ////[2021/2/1]添加折线图控件
            //else if(this.ModuleName=="折线图")
            //{
            //    GeneralIconSetting = new frmLineChart(this);
            //}
            else if(this.ModuleName == "开始" || this.ModuleName == "计数循环End" || this.ModuleName == "条件循环End" 
                || this.ModuleName == "双分支End1" || this.ModuleName == "双分支End2" || this.ModuleName == "单分支End")
            {

            }
            else
            {
                GeneralIconSetting = new frmConfig(this);
            }
            //初始化控件图标
            Image img;
           //InPic1=OutPic1都是小方块，InPic1与InPic2重叠，OutPic1与OutPic2重叠，不同状态下显示，平时只显示OutPic1
            //img = Image.FromFile(Directory.GetParent(Directory.GetParent(Application.StartupPath).FullName).FullName + @"\05-Image\ConnectImage\Usual.png");
            img = Image.FromFile(Globaldefine.exePath + @"Resource\ConnectImage\Usual.png");
            this.InPic1.Image = this.OutPic1.Image = img;
            this.IconInPic1Height = this.InPic1.Size.Height; 
            this.IconInPic1Width = this.InPic1.Size.Width;
            this.IconOutPic1Height = this.OutPic1.Size.Height;
            this.IconOutPic1Width = this.OutPic1.Size.Width;

            img = Image.FromFile(Globaldefine.exePath + @"Resource\ConnectImage\Out.png");
            this.OutPic2.Image = img;
            this.IconOutPic2Height = this.OutPic2.Size.Height;
           this.IconOutPic2Width = this.OutPic2.Size.Width;

           img = Image.FromFile(Globaldefine.exePath + @"Resource\ConnectImage\In.png");
            this.InPic2.Image = img;
            this.IconInPic2Height = this.InPic2.Size.Height;
            this.IconInPic2Width = this.InPic2.Size.Width;

            img = Image.FromFile(Globaldefine.exePath + @"Resource\ConnectImage\Note.png");
            this.notePic.Image = img;
            this.notePicWidth = this.notePic.Size.Width;
            this.notePicHeight = this.notePic.Size.Height;
            //20151203屏蔽OutPic2三角块输出连接点   //20151205把OutPic2三角块输出连接点放在图标下方
            this.OutPic1.MouseEnter += new EventHandler(OutPic1_MouseEnter);
            this.OutPic2.MouseLeave += new EventHandler(OutPic2_MouseLeave);
            this.OutPic2.MouseDown += new MouseEventHandler(OutPic2_MouseDown);
            this.OutPic1.Visible = true;
            this.InPic1.Visible = this.InPic2.Visible = this.OutPic2.Visible = false;//这些点只有鼠标移到相应位置才显示

            //在设计面板上显示控件图标
            //(1) 加载通用控件图片(Type==1-通用控件;Type==2-子程序控件)
            try
            { 
                if (IsSubFunc)
                {
                    IconFuncType = 2;
                }
                else
                {
                    IconFuncType = 1;
                }                                      //IconPicBox在Icon.cs中定义
                LoadCtrlImage(ModuleName, x, y, this.IconPicBox, this.MoveToIconPicBox, frm, IsSubFunc);//原函数在Icon.cs
                if ((!(this.GeneralIconType == TypeOfGeneralIcon.FlowControl)) && 
                    (!((ModuleName == "开始") && (this.GeneralIconType == TypeOfGeneralIcon.ExecuteIcon))))
                {  //不是"开始"控件，即为执行控件、通信控件等函数控件时，读取函数信息。
                    LoadCtrlFunc(ModuleName);//读取函数及函数参数等信息
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return;
            }
            //(2) 将图片加到窗体中
            frm.Controls.Add(this.IconPicBox);//IconPicBox包含了它的坐标位置，MoveToIconPicBox同样的信息
            frm.Controls.Add(this.MoveToIconPicBox);
            //(3) 加载连接点图片到控件图片上
            //开始控件不添加连入点图标    
           if (!((IconName == "开始") && (this.GeneralIconType == TypeOfGeneralIcon.ExecuteIcon)))
            {         //加入连入点图标，等待事件发生时显示   
                //20151205 接入连接点小图标，置于控件上方
                this.InPic1.Left = this.IconPicBox.Width/2 - this.InPic1.Width/2;
                this.InPic1.Top = 0;
                this.InPic2.Left = this.IconPicBox.Width / 2 - this.InPic2.Width / 2;
                this.InPic2.Top = 0;
                this.InPic2.MouseLeave += new EventHandler(InPic2_MouseLeave); //+= new表示：挂载事件，等待事件的发生
                this.InPic2.MouseUp += new MouseEventHandler(InPic2_MouseUp);
                this.InPic2.MouseMove += new MouseEventHandler(InPic2_MouseMove);
            }
            else    //为“开始”图标控件时，两个入接入点不可用。--151130
            {                    //20151203去除接入连接点小图标
                this.InPic1.Dispose();
                this.InPic2.Dispose();
            }
              //20151206
            this.OutPic1.Left = this.IconPicBox.Width / 2 - this.OutPic1.Width / 2;
            this.OutPic1.Top = this.IconPicBox.Height - this.OutPic1.Height;
            this.IconPicBox.Controls.Add(this.OutPic1);//加入输出连接点1,其他连接点在鼠标移动中显示
            this.OutPic2.Left = this.OutPic1.Left -2;
            this.OutPic2.Top = this.OutPic1.Top -4 ;
        }

        //释放资源
        public void Dispose()
        {
            this.IconPicBox.Dispose();
            this.MoveToIconPicBox.Dispose();
            this.InPic1.Dispose();
            this.InPic2.Dispose();
            this.OutPic1.Dispose();
            this.OutPic2.Dispose();
            this.notePic.Dispose();
        }
                
        /// <summary>重置父控件的基本信息</summary>
        public void ResetParent(GeneralIcon Icon) //有父控件,则清除父子关系和相关属性
        {
            //判断是否有父控件
            //有父控件,则清除父子关系和相关属性
            if (Icon.Parent != null)
            {
                //判断父控件的类型
                switch (Icon.ParentType)
                {
                    //父控件是通用控件
                    case LinkIconType.GeneralIcon:                      
                            ((GeneralIcon)(Icon.Parent)).Child = null;
                            ((GeneralIcon)(Icon.Parent)).ChildType = LinkIconType.NULL;
                        
                        break;
                    default:
                        MessageBox.Show("(GeneralIcon类中的方法)判断通用控件父控件类型时,通用控件的父控件类型出错！");
                        break;
                }
                Icon.Parent = null;
                Icon.ParentType = LinkIconType.NULL;
            }
        }

  /// <summary>删除节点控件后前后节点相连</summary>
        public void DelReConnect(GeneralIcon Icon) //20160328删除前建立前后节点的联系
        {
            if ((Icon.Child != null)&&(Icon.Parent != null))//建立新连接
            {
                ((GeneralIcon)(Icon.Parent)).Child = ((GeneralIcon)(Icon.Child));
                ((GeneralIcon)(Icon.Child)).Parent = ((GeneralIcon)(Icon.Parent));
            }

            else if (Icon.Child != null)//只有子节点
            {
                ((GeneralIcon)(Icon.Child)).Parent = null;
                ((GeneralIcon)(Icon.Child)).ParentType = LinkIconType.NULL;
            }    
            else if (Icon.Parent != null) //只有父节点
            {
                 ((GeneralIcon)(Icon.Parent)).Child = null;
                 ((GeneralIcon)(Icon.Parent)).ChildType = LinkIconType.NULL;
            }
            Icon.Parent = null;
            Icon.ParentType = LinkIconType.NULL;
            Icon.Child = null;
            Icon.ChildType = LinkIconType.NULL;
           
        }

        /// <summary>删除流程控件节点后前后节点相连</summary>
        public void DelLcReConnect(GeneralIcon Icon1,GeneralIcon Icon2) //20160328删除前建立前后节点的联系
        {
            if ((Icon2.Child != null) && (Icon1.Parent != null))//建立新连接
            {
                ((GeneralIcon)(Icon1.Parent)).Child = ((GeneralIcon)(Icon2.Child));
                ((GeneralIcon)(Icon2.Child)).Parent = ((GeneralIcon)(Icon1.Parent));
            }

            if ((Icon1.Parent == null)&&(Icon2.Child != null))//Icon1无父节点，最后一个被删节点有子节点，去除父节点
            {
                ((GeneralIcon)(Icon2.Child)).Parent = null;
                ((GeneralIcon)(Icon2.Child)).ParentType = LinkIconType.NULL;
            }
           if ((Icon1.Parent != null)&&(Icon2.Child == null))//第一个被删节点有父节点，去除与父节点的关系，Icon2无子节点
            {
                ((GeneralIcon)(Icon1.Parent)).Child = null;
                ((GeneralIcon)(Icon1.Parent)).ChildType = LinkIconType.NULL;
            }
           
        }
                
        /// <summary>重置子控件的基本信息</summary>
        public void ResetChild(GeneralIcon Icon)
        {
            //判断是否有子控件
            //(1) 有子控件,则清除父子关系和相关属性
            if (Icon.Child != null)
            {
                //判断子控件的类型
                switch (Icon.ChildType)
                {
                    //子控件是通用控件
                    case LinkIconType.GeneralIcon:
                        ((GeneralIcon)(Icon.Child)).Parent = null;
                        ((GeneralIcon)(Icon.Child)).ParentType = LinkIconType.NULL;
                        break;
                    default:
                        MessageBox.Show("(GeneralIcon类中的方法)判断通用控件子控件类型时,通用控件的子控件类型出错！");
                        break;
                }
                Icon.Child = null;
                Icon.ChildType = LinkIconType.NULL;
            }
        }

        /// <summary>重置图标控件的关系链</summary>
        public void ResettingRelation(GeneralIcon Icon)//置父控件对应的子控件数组下标，置子控件对应的父控件数组下标
        {
            if (Icon.Child != null)
            {
                //置通用控件中子控件的数组下标
                Icon.ChildIconArrNum = ((Icon)(Icon.Child)).IconArrNum;

                //遍历子控件
                switch (Icon.ChildType)
                {
                    //子控件是通用控件
                    case LinkIconType.GeneralIcon:
                        ((GeneralIcon)(Icon.Child)).ParentIconArrNum = Icon.IconArrNum;//子控件中父控件的数组下标
                        ((GeneralIcon)(Icon.Child)).ResettingRelation((GeneralIcon)(Icon.Child));
                        break;
                    default:
                        break;
                }
            }
        }
       
        ///==============================================================================
        /// <summary>
        /// 函数功能：递归生成图标对应的代码 2015-5-16 【GZF】
        /// </summary>
        /// <param name="text">生成的单行代码</param>
        /// <param name="Icon">图标</param>
        /// <param name="KongGeNum">每行代码要缩几个Tab符</param>
        /// <param name="flag">是否生成该通用控件本身的代码</param>
        /// <param name="count"></param>
        ///==============================================================================
        public void CreateCode(ref string text, GeneralIcon Icon,
            int KongGeNum, bool flag, ref int count)
        {
            int i;
            //20160510修改代码对齐
            string[] splitstrings = new String[10];            
            if ((Icon.ModuleName == "单分支End") || (Icon.ModuleName == "双分支End1") 
                || (Icon.ModuleName == "双分支End2") || (Icon.ModuleName =="计数循环End") 
                || (Icon.ModuleName == "条件循环End"))   KongGeNum -= 1;
            if (flag == true) //是否生成该通用控件本身的代码
            {
                //生成该通用控件本身的代码
                if(Icon.code != null&& Icon.code.InsertCode!="")
                {
                    splitstrings = Icon.code.InsertCode.Split('\n');
                    for (int j = 0; j < splitstrings.Length; j++)
                    {
                        //(1) 生成前导空格
                        //text += "\n";
                        for (i = 0; i < KongGeNum; i++)
                            text += "   ";
                        //(2) 生成单行通用控件的代码
                        text += splitstrings[j] + "\n";
                    }
                }

                //else
                //    splitstrings = Icon.code.InsertCode.Split('\n');//按分行符分割每行代码

            }
            //然后判断通用控件是否有子控件,如果有子控件,则根据子控件的类型,生成相应的子控件的代码 //20160510修改代码对齐
            if ((Icon.ModuleName == "单分支") || (Icon.ModuleName == "双分支") || (Icon.ModuleName == "双分支End1")|| 
                  (Icon.ModuleName == "计数循环") || (Icon.ModuleName == "条件循环"))
                KongGeNum += 1;

            if (Icon.Child != null)
            {
                //判断子控件的类型。使用了递归调用
                switch (Icon.ChildType)
                {
                    //子控件是通用控件,生成通用控件的代码
                    case LinkIconType.GeneralIcon:
                        ((GeneralIcon)(Icon.Child)).CreateCode(ref text, (GeneralIcon)(Icon.Child), KongGeNum, flag, ref count);                        
                        break;
                    default:
                        break;
                }
            }
        }
      
        ///==============================================================================
        #endregion

        #region GeneralIcon类的相关操作事件
        ///==============================================================================

        ///==============================================================================
        /// <summary>
        /// 触发条件：鼠标离开图标的1号输出连接点
        /// 函数功能：设置图形显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void OutPic1_MouseEnter(object sender, EventArgs e)
        {                  //这里GetContainerControl()返回sender父级，即frmGraphicProgrammer151202
            if (((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot == false)
            {                                                              //还没有连出连接线
                this.MoveToIconPicBox.Controls.Add(this.OutPic2);//加载连接输出点
                this.IconPicBox.Visible = false;//常态控件图片不可见，显示MoveToIconPicBox鼠标移动到控件上时显示的图片
                this.OutPic2.Visible = true;////显示连接输出点三角块
                this.OutPic1.Visible = false;//小方块 OutPic1不可见
                if (!((this.ModuleName == "开始") && (this.GeneralIconType == TypeOfGeneralIcon.ExecuteIcon)))
                {
                    this.InPic1.Visible = false;
                    this.InPic2.Visible = false;
                }
                this.MoveToIconPicBox.Visible = true;
            }
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：鼠标离开图标的2号输入连接点
        /// 函数功能：设置图形显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void InPic2_MouseLeave(object sender, EventArgs e)
        {
            this.IconPicBox.Controls.Add(this.OutPic1);
            this.OutPic1.Visible = true; //输出常态方形连接点可见
            this.OutPic2.Visible = false;//输出三角形连接点不可见
            if (!((this.ModuleName == "开始") && (this.GeneralIconType == TypeOfGeneralIcon.ExecuteIcon)))
            {                         //当鼠标离开输入连接点都不可见
                this.InPic2.Visible = false;
                this.InPic1.Visible = false;
            }
            this.MoveToIconPicBox.Visible = false;
            this.IconPicBox.Visible = true;
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：鼠标离开图标的2号输出连接点
        /// 函数功能：若为左键则准备起点，若为右键则取消连线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void OutPic2_MouseLeave(object sender, EventArgs e)
        {
            this.IconPicBox.Controls.Add(this.OutPic1);
            this.OutPic2.Visible = false;
            this.OutPic1.Visible = true;
            if (!((this.ModuleName == "开始") && (this.GeneralIconType == TypeOfGeneralIcon.ExecuteIcon)))
            {
                this.InPic1.Visible = false;
                this.InPic2.Visible = false;
            }
            this.MoveToIconPicBox.Visible = false;
            this.IconPicBox.Visible = true;
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：左键单击图标的2号输出连接点并未抬起时
        /// 函数功能：若为左键则准备起点，若为右键则取消连线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void OutPic2_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)//鼠标左击处理
            {
                if (!(((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot))
                {   //准备画贝塞尔曲线的起点，连线输出起点
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot = true;
                    //准备画线的起点，连线输出起点改为下方20151205
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).lineStartX = this.IconPicBox.Left + this.IconPicBox.Width/ 2;
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).lineStatrY =this.IconPicBox.Top + this.IconPicBox.Height ;
                   
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_OutIconModule = LineLinkIconType.GeneralIcon;
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_OutIcon = this;
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_OutIconModuleNum = this.IconArrNum;
                }
            }
            else if (e.Button == MouseButtons.Right)//鼠标右击处理
            {               //取消一条连线
                this.ResetChild(this);// 有子控件,则清除父子关系和相关属性
                Globaldefine.FrmParent.ActivedrmGraphicFlow.CreateCode();//生成代码
                Globaldefine.FrmParent.ActivedrmGraphicFlow.Update();
                Globaldefine.FrmParent.ActivedrmGraphicFlow.ReDraw();//绘制连线
            }
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：左键单击图标的2号输入连接点并抬起时
        /// 函数功能：完成连线操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void InPic2_MouseUp(object sender, MouseEventArgs e)
        {
            GeneralIcon tempIcon;
            tempIcon = this;//暂存连入节点
            //[2021/4/28]加入音效播放              
            sp.SoundLocation = Path.Combine(Globaldefine.exePath, "Config/click.wav");
            sp.Play();
            if (e.Button == MouseButtons.Left)//左键抬起---建立一条连线
            {
                //说明是相连的两个节点不必再连线20160328
                if (tempIcon.Parent == ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_OutIcon)
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot = false;

                else  //=====判断是否循环20160323======
                {
                    while (tempIcon.Child != null)
                    {

                        tempIcon = (GeneralIcon)tempIcon.Child;
                        if (tempIcon == ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_OutIcon)
                        {                // 出现循环，取消这次连线
                            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot = false;
                            break;   //避免环状连接，所造成的死循环
                        }
                    }
                    //=====判断是否循环结束 20160323======
                }

                if (((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot)
                {
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_InIconModule = LineLinkIconType.GeneralIcon;
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_InIcon = this;
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_InIconModuleNum = this.IconArrNum;
                    if (((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_InIcon.IconArrNum != ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_OutIcon.IconArrNum
                    || ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_InIconModule != ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_OutIconModule)
                    {
                        ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SetDrawRelation();//实现各节点的互联
                        ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot = false;
                    }
                    else
                    {
                        ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_InIconModule = LineLinkIconType.NULL;
                        ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).m_InIcon = null;
                    }
                   ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).ReDraw();

                }
            }
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：左键单击控件并未抬起时
        /// 函数功能：若为左键，且设置控件拖动标志为true。
        /// 若为右键则显示快捷菜单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void IconPicBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.MoveIcon = true;
            }
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：鼠标移动至控件，单击控件并抬起
        /// 函数功能：若为左键，且为控件拖动，则将选中的控件（要包括其）移动到指定位置。
        /// 若为右键则显示快捷菜单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        private void GeneralIconPicBox_MouseUp(object sender, MouseEventArgs e)
        {
            //设置控件组为当前的控件组，控件为当前的控件
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIconArr.Clear();//清除前面选中的控件
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIconNum = this.IconArrNum;
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIconType = LineLinkIconType.GeneralIcon;
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIcon = this;//设置选中图标为当前点击的控件

            //(1) 移动控件图片时,在鼠标弹起时,设置控件图片的新位置和相关属性
            if (e.Button == MouseButtons.Left && this.UpIcon)
            {
                {
                    //设置移动后的控件图片的位置属性
                    this.IconLeftDotNum = ((e.X + this.IconPicBox.Left) / (int)(Globaldefine.DotSize * 15)) - 2;
                    this.IconTopDotNum = ((e.Y + this.IconPicBox.Top) / (int)(Globaldefine.DotSize * 15)) - 2;

                    this.IconPicBox.Left = (int)(this.IconLeftDotNum * Globaldefine.DotSize * 15);
                    this.IconPicBox.Top = (int)(this.IconTopDotNum * Globaldefine.DotSize * 15);
                    this.MoveToIconPicBox.Left = this.IconPicBox.Left;
                    this.MoveToIconPicBox.Top = this.IconPicBox.Top;
                    if (this.notePic.Visible)
                    {
                        this.notePic.Left = this.IconPicBox.Left + this.IconPicBox.Width / 2 - this.notePic.Width / 2;
                        this.notePic.Top = this.IconPicBox.Top - this.notePic.Height * 3 / 5;
                    }
                    this.IconPicBox.Refresh();
                    this.MoveToIconPicBox.Refresh();
                    this.notePic.Refresh();
                    Globaldefine.FrmParent.ModifyProgrammer = true;
                    //如果移动的控件有父控件,设置父控件的子控件的接入点位置属性
                    if (this.Parent != null)
                    {
                        //判断父控件的类型
                        switch (this.ParentType)
                        {
                            //父控件是通用控件
                            case LinkIconType.GeneralIcon:
                                ((GeneralIcon)(this.Parent)).ChildDotX = this.IconLeftDotNum;
                                ((GeneralIcon)(this.Parent)).ChildDotY = this.IconTopDotNum + 2;
                                break;
                            default:
                                MessageBox.Show("GeneralIconPicBox_MouseUp事件中,移动控件完成时,控件父控件类型出错！");
                                break;
                        }
                    }
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).Update();
                    ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).ReDraw();
                }
                this.MoveIcon = false;   //清除鼠标左键单击控件事件
                this.UpIcon = false;     //清除拖动控件事件
            }
            else if (e.Button == MouseButtons.Right)   //若是鼠标右键抬起，则显示快捷菜单
            {
                if (this.IconArrNum != 0)
                {
                    GeneralIconContextMenuStrip.Show(this.MoveToIconPicBox, e.X, e.Y);//显示快捷菜单
                }
            }
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：鼠标移动至控件
        /// 函数功能：更改控件的显示，以提示用户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void IconPicBox_MouseEnter(object sender, EventArgs e)
        {
            //若首次单击窗体中控件的出口点（即处于连线状态），则更改控件显示的图片
            if (((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot)
            {   
                //若控件为执行控件，且不是“开始”控件，
                if (!((this.ModuleName == "开始") && (this.GeneralIconType == TypeOfGeneralIcon.ExecuteIcon)))
                {
                    this.MoveToIconPicBox.Controls.Add(this.InPic2);
                    this.InPic2.Visible = true;
                    this.InPic1.Visible = false;
                    this.OutPic1.Visible = false;
                }
                this.OutPic2.Visible = false;
                this.IconPicBox.Visible = false;
                this.MoveToIconPicBox.Visible = true;
            }
            else   //处于非连线状态
            {
                this.MoveToIconPicBox.Controls.Add(this.OutPic1);
                this.OutPic1.Visible = true;
                this.OutPic2.Visible = false;
                if (!((this.ModuleName == "开始") && (this.GeneralIconType == TypeOfGeneralIcon.ExecuteIcon)))
                {
                    this.InPic1.Visible = false;
                    this.InPic2.Visible = false;
                }
                this.IconPicBox.Visible = false;
                this.MoveToIconPicBox.Visible = true;
               //添加控件提示信息20160324======================================
                Globaldefine.labelvisible = true;
                Globaldefine.label_X = (int)((this.IconLeftDotNum + 8) * Globaldefine.DotSize * 15); //提示框坐标x
                Globaldefine.label_Y = (int)((this.IconTopDotNum) * Globaldefine.DotSize * 15); //提示框坐标y
                Globaldefine.labelstring = this.code.Comment;          // GeneralIconCode;
            
                //关联流程控件提示20160324======================================
                if ((this.ModuleName == "单分支")||(this.ModuleName == "双分支") ||
                   (this.ModuleName == "计数循环")|| (this.ModuleName == "条件循环"))
                {
                    GeneralIcon tempIcon;
                    //更改子控件的显示
                    tempIcon = (GeneralIcon)this.Child;
                    while (tempIcon.IconArrNum !=(this.IconArrNum + 1))
                     {
                         tempIcon.IconPicBox.Visible = false;
                         tempIcon.MoveToIconPicBox.Visible = true;
                         tempIcon = (GeneralIcon)tempIcon.Child;
                     }
                    if (this.ModuleName == "双分支")
                        while (tempIcon.IconArrNum != (this.IconArrNum + 2))
                        {
                            tempIcon.IconPicBox.Visible = false;
                            tempIcon.MoveToIconPicBox.Visible = true;
                            tempIcon = (GeneralIcon)tempIcon.Child;
                        }
                    tempIcon.IconPicBox.Visible = false;
                    tempIcon.MoveToIconPicBox.Visible = true;
                }                  
            }
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：鼠标离开控件
        /// 函数功能：更改控件的显示，以提示用户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void MoveToIconPicBox_MouseLeave(object sender, EventArgs e)
        {
            this.IconPicBox.Controls.Add(this.OutPic1);
            this.OutPic1.Visible = true;
            this.OutPic2.Visible = false;
            if (!((this.ModuleName == "开始") && (this.GeneralIconType == TypeOfGeneralIcon.ExecuteIcon)))
            {
                this.InPic1.Visible = false;
                this.InPic2.Visible = false;
            }
            this.MoveToIconPicBox.Visible = false;
            this.IconPicBox.Visible = true;
            Globaldefine.labelvisible = false;
            //关联流程控件提示20160324======================================
            if ((this.ModuleName == "单分支") || (this.ModuleName == "双分支") ||
               (this.ModuleName == "计数循环") || (this.ModuleName == "条件循环"))
            {                
                    GeneralIcon tempIcon;
                    tempIcon = (GeneralIcon)this.Child;
                    while ((tempIcon.IconArrNum != (this.IconArrNum + 1))&&(tempIcon != null))
                    {
                        tempIcon.IconPicBox.Visible = true;
                        tempIcon.MoveToIconPicBox.Visible = false;
                        tempIcon = (GeneralIcon)tempIcon.Child;
                        if (tempIcon == null)//防止控件被删除的情况20160324
                            break;
                    }
                    if ((this.ModuleName == "双分支")&&(tempIcon != null))
                        while (tempIcon.IconArrNum != (this.IconArrNum + 2))
                        {
                            tempIcon.IconPicBox.Visible = true;
                            tempIcon.MoveToIconPicBox.Visible = false;
                            tempIcon = (GeneralIcon)tempIcon.Child;
                            if (tempIcon == null)//防止控件被删除的情况20160324
                                break;
                        }
                    if (tempIcon != null)//防止控件被删除的情况20160324
                    {
                        tempIcon.IconPicBox.Visible = true;
                        tempIcon.MoveToIconPicBox.Visible = false;
                    }
                
            }
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：鼠标离开入口点
        /// 函数功能：更改入口点的显示，以提示用户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void InPic2_MouseMove(object sender, MouseEventArgs e)
        {
            if (((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).BFirstClickOutDot)
            {
                ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).lineEndX = e.X + this.InPic2.Left + this.MoveToIconPicBox.Left;
                ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).lineEndY = e.Y + this.InPic2.Top + this.MoveToIconPicBox.Top;
                ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).ReDraw();
            }
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：鼠标左键双击控件
        /// 函数功能：
        /// 控件后显示设置对话框，并将设置后的代码赋值给控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        private void MoveToIconPicBox_DoubleClick(object sender, EventArgs e)
        {
            this.info = Globaldefine.loadConfig.controlIconDic[ModuleName];
            string hardType = info.hard_type;
            //string hardType = "";
            //if (Globaldefine.FrmParent.InfoOfIconBox.controlIconDic.ContainsKey(ModuleName))
            //    hardType = Globaldefine.FrmParent.InfoOfIconBox.controlIconDic[ModuleName].controlHardType;
            this.MoveIcon = false;    //清除左键按住图标控件标志
            this.UpIcon = false;      //清除拖动图标控件标记
            if (((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIcon != null)
            {
                ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIcon.IconPicBox.BackColor = Color.Transparent;
                ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIcon.MoveToIconPicBox.BackColor = Color.Transparent;
            }
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIconNum = this.IconArrNum;
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIconType = LineLinkIconType.GeneralIcon;
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).SelectedIcon = this;
            //根据控件名打开不同的窗体【添加控件】
            if (this.ModuleName == "延时")
            {
                GeneralIconSetting = new frmTimedelaySet(this);
            }
            else if (this.ModuleName == "NB-IoT初始化")
            {
                GeneralIconSetting = new frmUEcomInit(this);
            }
            else if (this.ModuleName == "NB-IoT发送数据")
            {
                GeneralIconSetting = new frmUEcomSend(this);
            }
            else if (this.ModuleName == "WIFI初始化")
            {
                GeneralIconSetting = new frmUEcomInit(this);
            }
            else if (this.ModuleName == "WIFI发送数据")
            {
                GeneralIconSetting = new frmUEcomSend(this);
            }
            else if (this.ModuleName == "串口发送数据")
            {
                GeneralIconSetting = new frmUartSend(this);
            }
            else if (this.ModuleName == "接收到串口数据")
            {
                GeneralIconSetting = new frmUartRecv(this);
            }
            else if (this.ModuleName == "定时器时间到")
            {
                GeneralIconSetting = new frmTimeArrive(this);
            }
            else if (this.ModuleName == "接收到WIFI数据")
            {
                GeneralIconSetting = new frmUEcomRecv(this);
            }
            else if (this.ModuleName == "SPI发送数据")
            {
                GeneralIconSetting = new frmSPISend(this);
            }
            else if (this.ModuleName == "IIC")
            {
                GeneralIconSetting = new frmIIC(this);
            }
            else if (this.ModuleName == "LCD显示")
            {
                GeneralIconSetting = new frmLCD(this);
            }
            else if (this.ModuleName == "写入代码")
            {
                GeneralIconSetting = new frminput_code(this);
            }
            else if (this.ModuleName == "TSEV温度传感器")
            {
                GeneralIconSetting = new frmTESV(this);
            }
            else if (this.ModuleName == "条件循环")
            {
                GeneralIconSetting = new frmCnd_Loop(this);
            }
            else if ((this.ModuleName == "单分支") || (this.ModuleName == "双分支"))
            {
                GeneralIconSetting = new frmCnd_Loop(this);
            }
            else if (this.ModuleName == "计数循环")
            {
                GeneralIconSetting = new frmCountLoop(this);
            }
            else if (this.ModuleName == "定义函数")
            {
                GeneralIconSetting = new frmFunDefine(this);
            }
            else if (this.ModuleName == "调用函数")
            {
                GeneralIconSetting = new frmFunCall(this);
            }
            else if (this.ModuleName == "开始" || this.ModuleName == "计数循环End" || this.ModuleName == "条件循环End"
                || this.ModuleName == "双分支End1" || this.ModuleName == "双分支End2" || this.ModuleName == "单分支End")
            {

            }
            else if (this.ModuleName == "printf")
            {
                GeneralIconSetting = new frmPrintf(this);
            }
            else if (this.ModuleName == "定义变量")
            {
                GeneralIconSetting = new frmVariableInit(this);
            }
            else if (this.ModuleName == "设置变量")
            {
                GeneralIconSetting = new frmVariableSet(this);
            }
            else if (this.ModuleName == "数码管模块")
            {
                GeneralIconSetting = new frmDigit(this);
            }
            ////[2021/2/1]添加折线图控件
            //else if (this.ModuleName == "折线图")
            //{
            //    GeneralIconSetting = new frmLineChart(this);
            //}
            else  //新增可配置
            {
                GeneralIconSetting = new frmConfig(this);
            }
            //打开窗体并等待窗体正确结束，将窗体生成的代码拷贝到本构件对应的代码中
            //[2021/2/23]折线图更新setOption会跳转到这里出错
            //先暂时剔除折线图进入这里的情况&& this.ModuleName!= "折线图"
            if (GeneralIconSetting != null  && GeneralIconSetting.ShowDialog() == DialogResult.OK)
            {
                GeneralIconSetting.Close();
                Globaldefine.FrmParent.ModifyProgrammer = true;
            }
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).Update();
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).ReDraw();
            ((frmGraphicProgrammer)(((PictureBox)sender).GetContainerControl())).CreateCode(); //生成代码
        }

        ///==============================================================================
        /// <summary>
        /// 触发条件：在控件上右击，并选择右击菜单的某一项
        /// 函数功能：
        /// 修改时间：20160317
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///==============================================================================
        public void GeneralIconContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.ToString())
            {
                case "剪切":
                    Globaldefine.FrmParent.ContextString = "剪切";
                    break;
                case "复制":
                    Globaldefine.FrmParent.ContextString = "复制";
                    break;
                case "删除":
                    Globaldefine.FrmParent.ContextString = "删除";
                    break;
                default:
                    break;
            }
        }

        ///==============================================================================
        #endregion
    }
}
